package sms;
import java.util.*;
import javax.swing.*;


public class fangzhi_class {
	private int n=10;  //假设初始学生数量
	private Student[] fangzhi;  //声明有一个fangzhi班
	void set_n() {
		String s=JOptionPane.showInputDialog("请输入班级实际人数");
		n=Integer.parseInt(s);
		fangzhi=new Student[n+1];//创建了n+1个人的班级
	}
	void set_banji() {
		String s;
		for(int i=1;i<=n;i++) {
			fangzhi[i]=new Student();
			s=JOptionPane.showInputDialog("第"+i+"个学生学号：");
			while (!num.shuru_int(s)) {
				s=JOptionPane.showInputDialog("第"+i+"个学生学号：");
			}
			fangzhi[i].set_xuehao(Integer.parseInt(s));
			s=JOptionPane.showInputDialog("第"+i+"个学生姓名：");
			fangzhi[i].set_name(s);
			s=JOptionPane.showInputDialog("第"+i+"个学生语文成绩：");
			while (!num.shuru_int(s)) {
				s=JOptionPane.showInputDialog("第"+i+"个学生语文成绩：");
			}
			fangzhi[i].set_yuwen(Integer.parseInt(s));
			s=JOptionPane.showInputDialog("第"+i+"个学生数学成绩：");
			while (!num.shuru_int(s)) {
				s=JOptionPane.showInputDialog("第"+i+"个学生数学成绩：");
			}
			fangzhi[i].set_shuxue(Integer.parseInt(s));
			s=JOptionPane.showInputDialog("第"+i+"个学生计算机成绩：");
			while (!num.shuru_int(s)) {
				s=JOptionPane.showInputDialog("第"+i+"个学生计算机成绩：");
			}
			fangzhi[i].set_jisuanji(Integer.parseInt(s));
		}
	}
	public int get_n() {return n;}
	public Student[] get_stu(){ return fangzhi;  }
	//求出全班总分最高的学生是谁，并显示出其全部信息
	public Student get_max(fangzhi_class f){
		if(n<=0) {
			JOptionPane.showMessageDialog(null,"班级人数错误");
			return null;
		}
		else {
			Student s1=new Student();
			s1=f.fangzhi[1];
			for (int i=2;i<=n;i++) {
				if(f.fangzhi[i].get_sum()>s1.get_sum())
					s1=f.fangzhi[i];
			}
			return s1;
		}
	}
	public Student get_shuxue_max(fangzhi_class f) {
		//陈雪梅
		//获得数学最高分的同学
		if(n<=0) {
			JOptionPane.showMessageDialog(null, "学生人数错误");
			return null;
		}
		else
		{   Student s2=new Student();
			s2=f.fangzhi[1];
			for(int i=2;i<=n;i++) {
				if(f.fangzhi[i].get_shuxue()>s2.get_shuxue())
					s2=f.fangzhi[i];
			}
			return s2;
		}
	}
	//将全班学生的分数按平均分降序排列
	public Student score(fangzhi_class f) {
		if(n<=0) {
			JOptionPane.showMessageDialog(null,"班级人数错误");
			return null;
		}
		else {
			Student s3=new Student();
			s3=f.fangzhi[1];
			for (int i=2;i<=n;i++) {
				if(f.fangzhi[1].get_average()<=s3.get_average())
					s3=f.fangzhi[1];
			}
			return s3;
		}
	}

}
